const Service = require('egg').Service;

class DemoService extends Service {
  async index() {
    const { app } = this;
    const data = await app.mysql.query(`select * from users`)
    return { code: 0, msg: 'success', data }
  }
  async login() {
    const { app, ctx } = this;
    const { username, password } = ctx.request.body;
    const data = await app.mysql.query(`select * from users 
    where username=? and password=?`, [username, ctx.helper.getPassword(password)])

    if (data.length) {
      return {
        code: 0, msg: 'success',
      }
    } else {
      return {
        code: -1, msg: 'fail',
      }
    }
  }
}

module.exports = DemoService;